package com.quick.develop.flowable.framework.cmd;

import org.flowable.common.engine.impl.el.ExpressionManager;
import org.flowable.common.engine.impl.el.VariableContainerWrapper;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.util.CommandContextUtil;

import java.io.Serializable;
import java.util.Map;

/**
 * @author junyuan.liu
 * @description:  表达式获取值
 * @date 2022/6/27 18:46
 */
public class ExpressULCmd implements Command<Object>, Serializable {

    private static final long serialVersionUID = -7279981380543939684L;
    protected String conditionExpression;
    protected Map<String, Object> data;

    public ExpressULCmd(String conditionExpression, Map<String, Object> data) {
        this.conditionExpression = conditionExpression;
        this.data = data;
    }
    
    @Override
    public Object execute(CommandContext commandContext) {
        ExpressionManager expressionManager = CommandContextUtil.getProcessEngineConfiguration().getExpressionManager();

        return expressionManager.createExpression(conditionExpression)
                .getValue(new VariableContainerWrapper(data));
    }
}
